package BinarySearch;

import org.junit.Test;

public class _744_FindSmallestLetterGreaterThanTarget {
    //normal solution:bruce forced:solution passed.
    public char nextGreatestLetter1(char[] letters, char target) {
        char pos = letters[0];
        for (int i = 0; i < letters.length; i++) {
            if (letters[i] > target) {
                pos = letters[i];
                break;
            }
        }
        return pos;
    }

    //solution 2:using binary search
    public char nextGreatestLetter(char[] letters, char target) {
        int low = 0,high = letters.length-1;
        int middle = 0;
        while (low < high) {
            middle = low+(high-low)/2;
            if (letters[middle] <= target) {
                low = middle;
            } else {
                high = middle;
            }
        }
        if (letters[high] > target) {
            return letters[high];
        } else {
            return letters[0];
        }
    }

    @Test
    public void letterToIntText() {
        char a = 'a';
        char z = 'z';
        System.out.println(a>z?1:0);
    }
}
